<?php
/**
 +----------------------------------------------------------
 * 发票内容管理 model
 +----------------------------------------------------------
 * Time: 2016-05-31 
 +----------------------------------------------------------
 */
class invoice_mdl_content extends dbeav_model{
    
    var $defaultOrder = array('content_id',' asc');
    
    //选择了商品明细 无法进行删除操作
    public function pre_recycle($rows){
        
        $flag = true;
        $arr_content_ids = array();
        $rl_content = array();
        
        foreach ($rows as $var){
            if(intval($var["content_id"]) == 1){
                $flag = false;
                break;
            }
            $arr_content_ids[] = $var["content_id"];
            $rl_content[$var["content_id"]] = $var["content_name"];
        }
        if(!$flag){
            $this->recycle_msg = '商品明细必须存在 ，无法进行删除！';
            return false;
        }
        
        $mdlInOrderSet = app::get('invoice')->model('order_setting');
        $sql = "SELECT content_id FROM `sdb_invoice_order_setting` WHERE content_id IN(".implode(",",$arr_content_ids).") GROUP BY content_id";
        $rs_content = $mdlInOrderSet->db->select($sql);
        if(!empty($rs_content)){
            $used_content = array();
            foreach ($rs_content as $used_c){
                $used_content[] = $rl_content[$used_c["content_id"]];
            }
            $this->recycle_msg = implode("、",$used_content).'，已被应用，无法进行删除！';
            return false;
        }
        
        return true;
        
    }
    
}